﻿using Inovout.Cloud.DataStore.Models;
using Inovout.Cloud.DataStore.Services;
using Inovout.Cloud.DataWarehouse.Common;
using Inovout.Cloud.DataWarehouse.Models;
using Inovout.Models;
using Inovout.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.OData.Query;

namespace Inovout.Cloud.DataWarehouse.Services
{
    public class DataEntityService: IDataEntityService
    {
        private static readonly DataEntityService _instance = new DataEntityService();
        private IEntityService entityService = null;
        private IDataCollectionService dataCollectionService = null;
          
        private DataEntityService() 
        {
            entityService = ComponentRegistry.Resolve<IEntityService>();
            dataCollectionService = ComponentRegistry.Resolve<IDataCollectionService>();
        }

        public static DataEntityService GetInstance() 
        {
            return _instance;
        }

        public IQueryable QueryAll(string dataCollectionName)
        {
            //1.根据dataCollectionName查询对应需要返回的列和待查询的表
            //第一步 根据dataCollectionName查询数据
            DataCollection dataCollection = dataCollectionService.FindByName(dataCollectionName);
            if (dataCollection==null) 
            {
                //没有发布该数据集
                return null;
            }
            IQueryable queryAble = entityService.QueryAll(Constants.ProjectName, dataCollection.Table.Name);

            return queryAble;
        }
    }
}
